<?php
// +----------------------------------------------------------------------
// | [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Author 荒年 < 931274989@qq.com >
// +----------------------------------------------------------------------
// | Explain 云盟洗车核销导航页面
// +----------------------------------------------------------------------
namespace app\yunmeng\controller;

use app\yunmeng\model\YmCarlog as YmCasrlogModel;
use app\yunmeng\service\Jssdk;
use think\Controller;
use think\Db;

class Hexiao extends Controller
{
  public function index($id)
  {
    if($id > 0){
      $hex = Db::name('ym_xiche')->where('id','=',$id)->find();
      $this->assign('hex',$hex);
      return view();
    } else {
      $this->error('id错误');
    }
  }

  // 核销
  public function hex(){
    $post = input('post.');
    $model = new YmCasrlogModel();
    $xic = Db::name('ym_xiche')->where('id','=',$post['id'])->find();
    $Utel = Db::name('ym_user')->where('tel','=',$post['tel'])->find();
    if(empty($Utel)){
      return $this->error('尚未开通会员');
    }
    if($post['hexiao'] == $xic['hexiao']){
      Db::name('ym_xiche')->where('id','=',$post['id'])->setInc('cishu');
      $data['xid'] = $post['id'];
      $data['tel'] = $post['tel'];
      $model->save($data);
      $this->success('核销成功');
    } else {
      $this->error('核销码不正确');
    }
  }

  // 导航
  public function daohang(){
    $gps = Request()->param('gps');
    $chehang = Request()->param('name');
    $address = Request()->param('address');
    $jsSdk = new Jssdk(); 
    $json = $jsSdk->signature();
    $config = json_decode($json,true);
    $this->assign([
      'config' => $config,
      'gps' => $gps,
      'chehang' => $chehang,
      'address' => $address,
    ]);
    return view();
  }

}


?>